//@author A0101712B
#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Twentyfifth;
using namespace std;

namespace ParserUnitTest {
	TEST_CLASS(ParserUnitTest) {
public:
	//Weiling's unit testing
	TEST_METHOD(Parser_editTaskParseTesting) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 1 -start-time 2pm");
		string result = newCmd->toString();

		string expected = "Task ID: 1\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 14:00 00/00/0000\n";
		expected = expected + "End: -1:-1 00/00/0000\n";
		expected = expected + "Venue: \n";

		Assert::AreEqual(expected, result);
	}

	//boundary testing, time is 1159pm
	TEST_METHOD(Parser_editTaskParseTestingBoundary) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 1 -start-time 1159p.m.");
		string result = newCmd->toString();

		string expected = "Task ID: 1\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 23:59 00/00/0000\n";
		expected = expected + "End: -1:-1 00/00/0000\n";
		expected = expected + "Venue: \n";

		Assert::AreEqual(expected, result);
	}

	TEST_METHOD(Parser_searchTaskParseTesting) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("search swimming with friends");
		string result = newCmd->toString();
		string expected = "Id: 0\n";
		expected = expected + "Description: swimming with friends\n";

		Assert::AreEqual(expected, result);
	}

	//edited attributes simultaneously
	TEST_METHOD(Parser_editTaskParseTesting02) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 1 -start-time 2359 -start-date 31/12/2014");
		string result = newCmd->toString();

		string expected = "Task ID: 1\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 23:59 31/12/2014\n";
		expected = expected + "End: -1:-1 00/00/0000\n";
		expected = expected + "Venue: \n";

		Assert::AreEqual(expected, result);
	}

	//edited attributes simultaneously
	TEST_METHOD(Parser_editTaskParseTesting03) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 1 -start-time 2359 -start-date 31/12/2014 -end-time 2pm");
		string result = newCmd->toString();

		string expected = "Task ID: 1\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 23:59 31/12/2014\n";
		expected = expected + "End: 14:00 00/00/0000\n";
		expected = expected + "Venue: \n";

		Assert::AreEqual(expected, result);
	}


	//edited attributes simultaneously
	TEST_METHOD(Parser_editTaskParseTesting04) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 2 -start-time 2359 -start-date 31/12/2014 -end-time 2pm -end-date 02/12/2015");
		string result = newCmd->toString();

		string expected = "Task ID: 2\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 23:59 31/12/2014\n";
		expected = expected + "End: 14:00 02/12/2015\n";
		expected = expected + "Venue: \n";

		Assert::AreEqual(expected, result);
	}

	//edited attributes simultaneously
	TEST_METHOD(Parser_editTaskParseTesting05) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 2 -start-time 2359 -start-date 31/12/2014 -venue mpsh one -end-time 2pm -end-date 02/12/2015");
		string result = newCmd->toString();

		string expected = "Task ID: 2\n";
		expected = expected + "Description: \n";
		expected = expected + "Start: 23:59 31/12/2014\n";
		expected = expected + "End: 14:00 02/12/2015\n";
		expected = expected + "Venue: mpsh one\n";

		Assert::AreEqual(expected, result);
	}

	//edited attributes simultaneously
	TEST_METHOD(Parser_editTaskParseTesting06) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 54 -deadline-time 2359 -deadline-date 31/12/2014 -venue mpsh one");
		string result = newCmd->toString();

		string expected = "Task ID: 54\n";
		expected = expected + "Description: \n";
		expected = expected + "Deadline: 23:59 31/12/2014\n";
		expected = expected + "Venue: mpsh one\n";
		expected = expected + "State: [ ] \n";

		Assert::AreEqual(expected, result);
	}

	TEST_METHOD(Parser_editTaskParseTesting07) {
		int day;
		int month;
		int year;
		struct tm newtime;
		__time64_t long_time;
		errno_t err;
		// Get time as 64-bit integer.
		_time64(&long_time);
		// Convert to local time.
		err = _localtime64_s(&newtime, &long_time);
		if (err) {
			printf("Invalid argument to _localtime64_s.");
			exit(1);
		}

		struct tm* tempTime = &newtime;
		mktime(tempTime);
		newtime = *tempTime;

		day = newtime.tm_mday;
		month = newtime.tm_mon + 1;
		year = newtime.tm_year + 1900;

		char buffer[500];
		sprintf_s(buffer, "%02i/%02i/%04i", day, month, year);
		string date1 = buffer;


		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("edit 54 -description do 2103 hw -deadline-time 2359 -deadline-date today");
		string result = newCmd->toString();

		string expected = "Task ID: 54\n";
		expected = expected + "Description: do 2103 hw\n";
		expected = expected + "Deadline: 23:59 " + date1 + "\n";
		expected = expected + "Venue: \n";
		expected = expected + "State: [ ] \n";

		Assert::AreEqual(expected, result);
	}


	//boundary testing, all combinations of character, digits and symbols
	TEST_METHOD(Parser_searchTaskParseTestingBoundary1) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("search abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_");
		string result = newCmd->toString();
		string expected = "Id: 0\n";
		expected = expected + "Description: abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_\n";

		Assert::AreEqual(expected, result);
	}

	//boundary testing, all combinations of character, digits and symbols,with spaces
	TEST_METHOD(Parser_searchTaskParseTestingBoundary2) {
		// TODO: Your test code here
		Parser parser;
		Cmd* newCmd;
		newCmd = parser.parse("search abcdefghij klmnopqrstuvwx yz123456789 0!@# $%^&* ()_");
		string result = newCmd->toString();
		string expected = "Id: 0\n";
		expected = expected + "Description: abcdefghij klmnopqrstuvwx yz123456789 0!@# $%^&* ()_\n";

		Assert::AreEqual(expected, result);
	}
	};
}